package merlin.dao;

/**
 * Class to read data from a CSV file and enter the data in the database table
 *
 */

import java.io.*;
import java.sql.*;

public class ReportTitlesDataEntry {
	
	public static void main(String[] args){
		try{
			BufferedReader br = new BufferedReader(new FileReader(args[0]));
			System.out.println("Opened file " + args[0]);
			Connection con = ConnectionPool.getConnectionPool().getConnection();
			System.out.println("connected to db");
			PreparedStatement stmt = con.prepareStatement("insert into REPORT_TITLES(REPORT_TITLES_ID,REPORT_TITLE) values(?,?)");
			String line = null;
			con.setAutoCommit(false);
			while((line = br.readLine())!= null){
				String arr[] = line.split(",");
				stmt.setInt(1,Integer.parseInt(arr[0]));
				stmt.setString(2,arr[1]);
				stmt.addBatch();
			}
			stmt.executeBatch();
			con.commit();
			
			stmt.close();
			con.close();
			System.out.println("done");
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}
